package io.github.ali.commons.bean;

public class ModifiableBean<T> {

	private T value;

	public ModifiableBean(T value) {
		this.value = value;
	}

	public T get() {
		return value;
	}

	public T modify(T value) {
		this.value = value;
		return this.value;
	}
	/**
	 * Integer|Long类型对象才执行累加
	 */
	@SuppressWarnings("unchecked")
	public void accumulate() {
		if (value != null && value instanceof Byte) {
			Byte iValue = (Byte) value;
			iValue++;
			value = (T) iValue;
		} else if (value != null && value instanceof Short) {
			Short iValue = (Short) value;
			iValue++;
			value = (T) iValue;
		} else if (value != null && value instanceof Integer) {
			Integer iValue = (Integer) value;
			iValue++;
			value = (T) iValue;
		} else if (value != null && value instanceof Long) {
			Long iValue = (Long) value;
			iValue++;
			value = (T) iValue;
		} else if (value != null && value instanceof Float) {
			Float iValue = (Float) value;
			iValue++;
			value = (T) iValue;
		} else if (value != null && value instanceof Double) {
			Double iValue = (Double) value;
			iValue++;
			value = (T) iValue;
		}
	}
}
